[#include "../../../common/html.ftl" /]
[@html]
    [@head title="用户分配角色" css=["fw", "bootstrap-table"] /]
    [@body]
        [@main ]
            <div class="fw-tables">
                [@dataForm formId="form-user-editPwd" ]
                    <input type="hidden" name="userId" value="${sysUser.userId!}" />
                    <div class="am-form-group am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <label>登录账号：</label>
                        <input class="am-form-field am-radius" type="text" name="loginName" value="${sysUser.loginName!}" readonly/>
                    </div>
                    <div class="am-form-group am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <label>用户姓名：</label>
                        <input class="am-form-field am-radius" type="text" name="userName" value="${sysUser.userName!}" readonly/>
                    </div>
                    <div class="am-form-group am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <hr data-am-widget="divider" style="" class="am-divider am-divider-default" />
                    </div>
                    <div class="am-form-group am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="fw-table">
                            <table id="bootstrap-table"></table>
                        </div>
                    </div>
                [/@dataForm]

        [/@main]

        [#--PC/APP 右侧悬浮按钮--]
        [@rightToolbar /]

        [@script js=["fw", "bootstrap-table"]]
            <script type="text/javascript">
                var prefix = ctx + "osfw/system/manage/user/authRole";
                var userRoles = ${convert.toJson(roles)};

                $(function() {
                    var options = {
                        uniqueId: "roleId",
                        url: ctx + "osfw/system/manage/role/listUser",
                        showSearch: false,
                        showRefresh: false,
                        showToggle: false,
                        showColumns: false,
                        pagination: false,
                        clickToSelect: true,
                        columns: [
                            {
                                checkbox: true,
                                formatter:function (value, row, index) {
                                    for (var i = 0; i < userRoles.length; i++) {
                                        if (userRoles[i].roleId == row.roleId) {
                                            return { checked: true };
                                        }
                                    }
                                    return { checked: false };
                                }
                            },
                            {
                                title: "序号",
                                formatter: function (value, row, index) {
                                    return $.table.serialNumber(index);
                                }
                            },
                            {
                                field: 'roleName',
                                title: '角色名称',
                                sortable: true
                            },
                            {
                                field: 'createBy',
                                title: '创建人'
                            },
                            {
                                field: 'createTime',
                                title: '创建时间',
                                sortable: true
                            }
                        ]
                    };
                    $.table.init(options);
                });

                /* 添加角色-提交 */
                function submitHandler() {
                    table.set();
                    var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
                    var data = { "userId": ${user.userId!}, "roleIds": rows.join() };
                    $.operate.save(prefix + "/insertAuthRole", data);
                }

            </script>
        [/@script]
    [/@body]
[/@html]
